package org.csu.mypetstore.web.Filter;

import org.csu.mypetstore.persistence.AccountDao;
import org.csu.mypetstore.persistence.impl.AccountDaoImpl;
import org.csu.mypetstore.tools.WebLog;

import javax.servlet.*;
import java.io.IOException;

public class MainFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        AccountDao accountDao = new AccountDaoImpl();

        //System.out.println("------filter--------"+username+"----------");
        if(accountDao.getAccountByUsernameAndPassword(username,password)!=null) {
            String message = username + "登录网站";
            WebLog.WriteWebLog(message);
        }

        chain.doFilter(req, resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
